<?php

class distribute_task extends spModel
{
	public $pk = "id"; // 数据表的主键
    public $table = "distribute_task"; // 数据表的名称

	function create($row) {
		//缴纳押金
		$mDeposit = spClass('deposit');
		if ($mDeposit->find(array('uid'=>$row['uid']))) {
			$mDeposit->runSql("UPDATE deposit SET amount = amount + " . $row['bonus_total'] . " WHERE uid = " . $row['uid']);
		} else {
			$mDeposit->create(array('uid'=>$row['uid'], 'amount'=>$row['bonus_total']));
		}

		$mUser = spClass('user');
		$mUser->runSql("UPDATE user SET cash = cash-".$row['bonus_total']." WHERE uid = ".$row['uid']);

		$mUserLog = spClass('userlog');
		$logArray	  = array(
							'uid' => $row['uid'],
							'type'=> 'pub-distribute',
							'content' => 'Published total '.$row['bonus_total'].' per '.$row['bonus'].'weibi for distribute blog '.$row['blogurl'],
							'dateline'=> time()
						);
		$lastLogId    = $mUserLog->create($logArray);

		$cashLogArray	  = array(
							'uid' => $row['uid'],
							'logid' => $lastLogId,
							'amount'=> -$row['bonus_total'],
							'dateline'=> time()
						);
		$mUserCashLog = spClass('usercashlog');
		$mUserCashLog->create($cashLogArray);

		parent::create($row);
	}
}